<template>
  <div class="header-nav">
    <nav>
      <a @click="jumpHome()">安复心理</a>
      <div
        v-for="(item, index) in menu"
        :key="index"
        @click="jumpPage(index)"
        :class="[menuIndex==index?'navActive':'']"
      >{{item.title}}</div>
      <span class="iconfont menu-btn" :class="[isBtn?'icon-close':'icon-menu']" @click="menuBtn()"></span>
    </nav>
    <div class="menu-box" :class="[isBtn?'menuActive':'']">
      <ul class="menu">
        <li v-for="(item, index) in menu" :key="index" @click="jumpPage(index)">{{item.title}}</li>
      </ul>
    </div>
  </div>
</template>
<script>
import { mapState } from "vuex";
export default {
  name: "header-nav",
  data() {
    return {
      isBtn: false,
      menu: [
        { title: "首页", routerName: "home" },
        { title: "项目介绍", routerName: "project" },
        { title: "公司介绍", routerName: "introduce" },
        { title: "团队组成", routerName: "team" }
      ]
    };
  },
  computed: mapState(["menuIndex"]),
  methods: {
    menuBtn() {
      this.isBtn = !this.isBtn;
      if (this.isBtn) {
        document.querySelector("body").style.overflow = "hidden";
      } else {
        document.querySelector("body").style.overflow = "auto";
      }
    },
    jumpPage(i) {
      this.$store.commit("changeIndex", i);
      this.$router.push(this.menu[i].routerName);
      this.isBtn = false;
    },
    jumpHome() {
      this.$router.push("home");
    }
  },
  mounted() {
    document.querySelector("body").style.overflow = "auto";
  }
};
</script>
<style scoped>
.header-nav {
  position: fixed;
  z-index: 3;
  padding: 0 30px;
  box-sizing: border-box;
  width: 100%;
  height: 60px;
  background-color: #26a0a9;
}
.header-nav nav {
  font-size: 16px;
  height: 60px;
  line-height: 60px;
  color: #fff;
}

nav a {
  float: left;
  text-align: center;
  cursor: pointer;
  font-weight: bold;
  font-size: 21px;
  color: #fff;
  margin-right: 30px;
  width: 110px;
}

nav div {
  text-align: center;
  float: left;
  width: 100px;
  cursor: pointer;
  margin-right: 40px;
}
.navActive {
  text-shadow: 0 0 10px #fff;
}
nav .menu-btn {
  display: none;
  float: right;
  text-align: center;
  font-size: 24px;
  width: 50px;
  height: 100%;
}

.menu-box {
  position: fixed;
  z-index: 3;
  top: 52px;
  left: 0;
  height: 0;
  width: 100%;
  overflow: hidden;
  background-color: #eee;
  transition: all 0.3s ease;
}
.menuActive {
  height: calc(100vh - 52px);
}
.menu-box .menu {
  margin-left: 43px;
  margin-top: 61px;
}

.menu-box .menu li {
  line-height: 47px;
  color: #666;
  font-size: 21px;
  cursor: pointer;
}

@media screen and (max-width: 1024px) {
  .header-nav,
  nav {
    height: 52px !important;
  }
  nav {
    line-height: 52px !important;
  }
  nav div {
    display: none;
  }
  nav .menu-btn {
    display: block;
  }
}
</style>